/**
    [Filename]
    Purpose: [Purpose]

    @author Jason Wojcik
    @version [version]
*/

#include "CApp.h"
#include "Define.h"

bool CApp::C4Init(){

    //reinitialize variables
    turn = 0;
    wonGame = false;
    CEntity::EntityList.clear();
    chips.clear();
    testString.str(std::string());

    //Load the area
    if(CArea::AreaControl.OnLoad("./maps/c4_gameboard.area") == false) {
        return false;
    }

    //Load the animated arrow
    if(arrow.OnLoad("./gfx/arrow_down.png",48,48,4) == false) return false;
    arrow.Y = TILE_SIZE/2;
    arrow.Flags = ENTITY_FLAG_MAPONLY;
    arrow.RenderOn = true;


    //Load the win graphic
    if(win.OnLoad("./gfx/win.png",640,480,1) == false) return false;
    win.Type = ENTITY_TYPE_IMAGE;

    //(re)populate the chips vector
    for(int i = 0; i < NUMBER_CHIPS; i++){
        CChip temp;
        chips.push_back(temp);
    }

    //Load the chip entities
    for(int i = 0; i < chips.size(); i++){
        if(chips[i].OnLoad("./gfx/c4_chips.png", 64, 64, 1) == false){
            return false;
        }
    }

    //set initial position
    chips[0].X += 3*TILE_SIZE;

    //add Entities
    CEntity::EntityList.push_back(&arrow);
    CEntity::EntityList.push_back(&chips[0]);
}

bool CApp::OnInit(){

    //initialize SDL
    if(SDL_Init(SDL_INIT_EVERYTHING) < 0) return false;

    //initialize the font
    if(TTF_Init() == -1) return false;
    font = TTF_OpenFont("./font/arial.ttf", FONT_SIZE);
    TTF_SetFontStyle(font, TTF_STYLE_BOLD);

    //initialize the screen
    if((Surf_Display = SDL_SetVideoMode(WWIDTH,WHEIGHT,32,SDL_HWSURFACE |
        SDL_DOUBLEBUF)) == NULL){
            return false;
        }

    //Change caption
    SDL_WM_SetCaption("Connect Four", NULL);

    //initialze the C4Game
    if(C4Init() == false) //return false;


    /* YOSHI
    //Add player 1
    if(Player.OnLoad("./gfx/yoshi.png", 64, 64, 8) == false) {
        return false;
    }
    CEntity::EntityList.push_back(&Player);

    //Add player 2
    if(Player2.OnLoad("./gfx/yoshi.png", 64, 64, 8) == false) {
        return false;
    }
    Player2.X = 350;
    CEntity::EntityList.push_back(&Player2);

    //Set Camera parameters
    //CCamera::CameraControl.TargetMode = TARGET_MODE_CENTER;
    //CCamera::CameraControl.SetTarget(&Player.X, &Player.Y);

    //Load the area
    if(CArea::AreaControl.OnLoad("./maps/1.area") == false) {
    return false;
    }
    */

    //Allow keypresses to be continuous
    //SDL_EnableKeyRepeat(1, SDL_DEFAULT_REPEAT_INTERVAL / 3);

    return true;
}
